package com.uwin.findTomcat;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.alibaba.fastjson.JSON;

@SuppressWarnings("serial")
public class Free implements Serializable{
	
	public static final String CMD = "free -m";
	private static final String REG = "\\d+";
	
	public static Free reslvos(RemoteExecuteCommand rec){
		
		String exResult = //"Mem:         15926       8694       7231          0          1       4499";
				rec.executeSuccessList(CMD).get(1);
		
		Free free = new Free();
		Pattern pattern = Pattern.compile(REG);
		Matcher matcher = pattern.matcher(exResult);
		if (matcher.find()){
			free.setTotal(Long.parseLong(matcher.group()));
			matcher.find();
			free.setUsed(Long.parseLong(matcher.group()));
			matcher.find();
			free.setFree(Long.parseLong(matcher.group()));
			matcher.find();matcher.find();matcher.find();
			free.setCached(Long.parseLong(matcher.group(0)));
		}
		return free;
	}
	public static void main(String[] args) {
		Free free = reslvos(null);
		System.out.println(JSON.toJSONString(free));
	}
	

	private Long total;
	private Long used;
	private Long free;
	private Long cached;
	public Long getTotal() {
		return total;
	}
	public void setTotal(Long total) {
		this.total = total;
	}
	public Long getUsed() {
		return used;
	}
	public void setUsed(Long used) {
		this.used = used;
	}
	public Long getFree() {
		return free;
	}
	public void setFree(Long free) {
		this.free = free;
	}
	public Long getCached() {
		return cached;
	}
	public void setCached(Long cached) {
		this.cached = cached;
	}
	
	
	
	
}
